package ve.gob.cne.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;


public class ApplicationProperties {

	private static Properties properties = init();

	private ApplicationProperties() {
	}

	private static Properties init() {
		Properties properties = new Properties();
		try {
			InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("ApplicationResources.properties");
			properties.load(in);
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return properties;
	}

	public static String getProperty(String key) {
		return properties.getProperty(key);
	}

	public static void writeProperty(String propertyName, String propertyValue) {
		try {
			File f = new File("classpath:ApplicationResources.properties");
//			System.out.println(f.getAbsolutePath());
			OutputStream out = new FileOutputStream(f);
			properties.setProperty(propertyName, propertyValue);
			properties.store(out, "");
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}